package com.kfm.jdbc.day0403;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;

import java.io.IOException;

public class Demo09 {

    public static void main(String[] args) {
        // 通过 json 实现深拷贝
        Computer computer = new Computer();
        computer.name = "联想";
        computer.price = 5000.0;
        Cpu cpu = new Cpu();
        cpu.name = "i7-7700";
        computer.cpu = cpu;

        System.out.println(computer);

        // Gson 实现深拷贝
        Gson gson = new Gson();
        // Object --> json 字符串
        String json = gson.toJson(computer);
        // json 字符串 --> Object
        Computer clone = gson.fromJson(json, Computer.class);

        System.out.println(clone);


    }
}
